import { loginData } from '@/api/common'
export default {
  namespaced: true,
  state: () => ({
    userinfo: null
  }),
  getters: {
    userInfos: (state) => {
      return state.userinfo
    }
  },
  mutations: {
    setUserInfo (state, info) {
      state.userinfo = info
    }
  },
  actions: {
    setAsyncUserInfo ({ state, commit }, info) {
      return new Promise((resolve, reject) => {
        loginData().then((res) => {
          if (res.data.code === 200) {
            commit('setUserInfo', res.data.data)
            resolve(res.data.data)
          }
        }).catch((error) => {
          console.log(error)
          reject(error)
        })
      })
    }
  }
}
